/*
 * Copyright (C), 2002-2013, 苏宁易购电子商务有限公司
 * FileName: MongodbConfiger.java
 * Author:   12070644@cnsuning.com
 * Date:     2013-9-27 上午00:00:00
 */
package com.suning.sawp.service.mongodb;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.mongodb.core.MongoTemplate;

import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;

/**
 * Mongodb配置类
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 *
 * @author 12070644@cnsuning.com
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class MongodbConfiger implements InitializingBean {
    /**
     * mongoTemplate
     */
    private MongoTemplate mongoTemplate;
    
    private MongoTemplate safeMongoTemplate;

    /**
     * afterPropertiesSet
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        mongoTemplate.setReadPreference(ReadPreference.secondaryPreferred());
        safeMongoTemplate.setReadPreference(ReadPreference.primaryPreferred());
        safeMongoTemplate.setWriteConcern(WriteConcern.SAFE);
    }

    /**
     * @param 
     * mongoTemplate the mongoTemplate to set
     */
    public void setMongoTemplate(MongoTemplate mongoTemplate) {
        this.mongoTemplate = mongoTemplate;
    }
    
    public void setSafeMongoTemplate(MongoTemplate safeMongoTemplate) {
        this.safeMongoTemplate = safeMongoTemplate;
    }

}
